package com.linkgie.galaxyframework.utils.log;

import java.util.Collection;
import java.util.Iterator;
import java.util.function.Function;

import com.linkgie.galaxyframework.utils.CollectionUtils;

public final class SystemConsole {
	
	private SystemConsole() {
	}


	public static void debug(Collection<String> items, String promptFormat, Object... args) {
		debug(items.iterator(), promptFormat, args);
	}

	public static void debug(String[] items, String promptFormat, Object... args) {
		debug(CollectionUtils.iterator(items), promptFormat, args);
	}

	public static  <T> void debug(Collection<T> items, Function<T, String> toStringFunction, String promptFormat, Object... args) {
		debug(CollectionUtils.iterator(items, toStringFunction), promptFormat, args);
	}

	public static  <T> void debug(T[] items, Function<T, String> toStringFunction, String promptFormat, Object... args) {
		debug(CollectionUtils.iterator(items, toStringFunction), promptFormat, args);
	}

	public static  void debug(Iterator<String> items, String promptFormat, Object... args) {
		String prompt = String.format(promptFormat, args);
		long debugId = System.currentTimeMillis();
		System.out.println();
		System.out.println(String.format("------------------ [debug-%s] %s ------------------", debugId, prompt));
		
		while(items.hasNext()){
			System.out.println(items.next());
		}

		long elapsed = System.currentTimeMillis() - debugId;
		System.out.println(String.format("----------------------- [debug-%s][elapsed: %s ms] -----------------------", debugId, elapsed));
		System.out.println();
	}

	
	public static void info(String format, Object...args) {
		String message = String.format(format, args);
		System.out.println(message);
	}
	public static void error(String format, Object...args) {
		String message = String.format(format, args);
		System.err.println(message);
	}
	
	public static void error(String message, Throwable error) {
		System.err.println(message);
		error.printStackTrace(System.err);
	}
	
	
	public static void error(Throwable error, String format, Object...args) {
		String message = String.format(format, args);
		System.err.println(message);
		error.printStackTrace(System.err);
	}
}
